﻿namespace USElections.Model
{
    using System.Collections.ObjectModel;

    /// <summary>
    /// Candidates class.
    /// </summary>
    public class Candidates : ObservableCollection<Candidate>
    {
        /// <summary>
        /// Gets candidate by candidate id.
        /// </summary>
        /// <param name="id">The candidate id.</param>
        /// <returns>The candidate object.</returns>
        public Candidate GetCandidateById(int id)
        {
            foreach (Candidate candidate in this)
            {
                if (candidate.Id == id)
                {
                    return candidate;
                }
            }

            return null;
        }

        /// <summary>
        /// Gets candidate object by full name of candidate.
        /// </summary>
        /// <param name="fullname">The candidates full name.</param>
        /// <returns>The candidate object.</returns>
        public Candidate GetCandidateByFullname(string fullname)
        {
            foreach (Candidate candidate in this)
            {
                if (string.Compare(fullname, candidate.FullName, System.StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    return candidate;
                }
            }

            return null;
        }
    }
}
